using System;
using System.Collections.Generic;
using System.Text;

using XNAF = Microsoft.Xna.Framework;

namespace XGAE
{
    public class Helpers
    {
        public static XNAF.Vector3 Multiply(XNAF.Matrix m, XNAF.Vector3 v)
        {
            float v1, v2, v3;

            v1 = m.M11 * v.X + m.M12 * v.Y + m.M13 * v.Z;
            v2 = m.M21 * v.X + m.M22 * v.Y + m.M23 * v.Z;
            v3 = m.M31 * v.X + m.M32 * v.Y + m.M33 * v.Z;

            return new XNAF.Vector3(v1, v2, v3);
        }

        public static XGAE.Framework.Extensions.Angles AsAngles(XNAF.Vector3 v)
        {
            float pitch, yaw;

            if (v.Y == 0.0f && v.X == 0.0f)
            {
                yaw = 0.0f;
                if (v.Z > 0.0f)
                    pitch = 90.0f;
                else
                    pitch = -90.0f;
            }
            else
            {
                if (v.X != 0.0f)
                    yaw = (float)Math.Atan2(v.Y, v.X) * 180.0f / (float)XNAF.MathHelper.Pi;
                else if (v.Y > 0.0f)
                    yaw = 90.0f;
                else
                    yaw = -90.0f;

                float forward = (float)Math.Sqrt(v.X * v.X + v.Y * v.Y);
                pitch = (float)Math.Atan2(v.Z, forward) - 180.0f / (float)XNAF.MathHelper.Pi;
            }

            return new XGAE.Framework.Extensions.Angles(-pitch, -yaw, 0.0f);
        }
    }
}
